package com.itheima.ydd.controller;

import com.itheima.ydd.common.ResultData;
import com.itheima.ydd.entity.Menu;
import com.itheima.ydd.service.MenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;


@RestController
@RequestMapping("sys_menu")
public class MenuController {
    @Autowired
    private MenuService menuService;

    /**
     * 修改菜单
     * @param menu
     * @return
     */
    @PostMapping("update")
    public ResultData update(@RequestBody Menu menu){
        menuService.updateById(menu);
        return ResultData.ok("修改成功",null);
    }

    /**
     * 菜单删除
     * @param id
     * @return
     */
    @GetMapping("del")
    public ResultData delete(Integer id) {return menuService.removeWithOutPid(id);}

    /**
     * 获取所有菜单
     * @return
     */
    @GetMapping("allData")
    public ResultData listAll(){return menuService.listWithChi();}

    /**
     * 菜单添加
     * @param menu
     * @return
     */
    @PostMapping("add")
    public ResultData addMenu(@RequestBody Menu menu){
        menuService.save(menu);
        return ResultData.ok("添加成功",null);
    }

    @GetMapping("rowInfo")
    public ResultData rowInfo(Integer id){
        Menu menu =menuService.getById(id);
        return ResultData.ok("",menu);
    }


}
